setTimeout(function() {
	function getID() {
		var vars = {};
		var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
			vars[key] = (value==undefined)?null:value;
		});
		return vars;
	}
	jQuery.fn.center = function () {
		this.css("position","absolute");
		this.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + "px");
		this.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + "px");
		return this;
	};
	function hide() {
		document.body.ondblclick = function() {
			if(document.body.scrollHeight - document.body.scrollTop == document.body.clientHeight) window.scrollTo(0, 0);
			else window.scrollTo(0, document.body.scrollHeight);
		};
		$("div#__OUSCBACK__").hide();
		$("div#__OUSCSET__").hide();
		$(document.documentElement).css({overflow: "scroll"});
	}
	function show() {
		document.body.ondblclick = function(e) {
			var evt = e || window.event;
			e.preventDefault();
		};
		$("div#__OUSCBACK__").show();
		$("div#__OUSCSET__").show();
		$(document.documentElement).css({overflow: "hidden"});
	}
	var OUShortCut = function() {
		this.constructor.params = null;
		this.version = "1.0.0";
		this.getParam = function(key) {
			return this.constructor.params[key];
		};
		this.setParam = function(key, value) {
			this.constructor.params[key] = value;
		};
		this.init = function(params) {
			this.constructor.params = params;
			var page = (params['page'] || 1);
			page = parseInt(page, 10);
			this.setParam("page", page);
			if(typeof(localStorage) == "undefined") return;
			else {
				if(localStorage.getItem("OUSCVerCheck") == null) this.alertUpdate();
				else if(localStorage.getItem("OUSCVerCheck") != this.version) this.alertUpdate();
				this.viewCtrlPanel();
				this.viewLink();
			}
		};
		this.alertUpdate = function() {
			localStorage.setItem("OUSCVerCheck", this.version);
			window.alert("OUSC v"+this.version+" 업데이트(&설치) 완료!");
		};
		this.viewLink = function() {
			var $scLink = $("<a />").text("단축키설정").css({cursor: "pointer"}).unbind("click").click(function() {
				show();
			});
			$("a:contains('자동로그인')").parent().append(" | ", $scLink);
		};
		this.viewCtrlPanel = function() {
			var $back = $("<div />").attr("id", "__OUSCBACK__").css({width: "100%", height: "100%", backgroundColor: "white", opacity: "0.85", zIndex: 1000000, left: 0, top: 0, position: "fixed"});
			var $setBtn = $("<input />").attr("type", "submit").val("설정").css({font: "bold 10pt '굴림'", padding: "10px 0", width: "50%"});
			var $closeBtn = $("<input />").attr("type", "button").val("닫기(Esc)").css({font: "normal 10pt '굴림'", padding: "10px 0", width: "50%"}).unbind("click").click(function() {
				hide();
			});
			var $setForm = $("<form />").css("margin", 0).html("<table>"+
			"<tr><th>숫자키</th><th>게시판 ID / URL (현재 : <strong>"+this.getParam("table")+"</strong>)</th></tr>"+
			"<tr style='background-color: #E0E0E0;'><td class='key'>0</td><td><input type='text' id='OUSCURI0' class='OUSCURI' value='"+(localStorage.getItem("OUSC0")||"")+"' /></td></tr>"+
			"<tr style='background-color: #FFFFFF;'><td class='key'>1</td><td><input type='text' id='OUSCURI1' class='OUSCURI' value='"+(localStorage.getItem("OUSC1")||"")+"' /></td></tr>"+
			"<tr style='background-color: #E0E0E0;'><td class='key'>2</td><td><input type='text' id='OUSCURI2' class='OUSCURI' value='"+(localStorage.getItem("OUSC2")||"")+"' /></td></tr>"+
			"<tr style='background-color: #FFFFFF;'><td class='key'>3</td><td><input type='text' id='OUSCURI3' class='OUSCURI' value='"+(localStorage.getItem("OUSC3")||"")+"' /></td></tr>"+
			"<tr style='background-color: #E0E0E0;'><td class='key'>4</td><td><input type='text' id='OUSCURI4' class='OUSCURI' value='"+(localStorage.getItem("OUSC4")||"")+"' /></td></tr>"+
			"<tr style='background-color: #FFFFFF;'><td class='key'>5</td><td><input type='text' id='OUSCURI5' class='OUSCURI' value='"+(localStorage.getItem("OUSC5")||"")+"' /></td></tr>"+
			"<tr style='background-color: #E0E0E0;'><td class='key'>6</td><td><input type='text' id='OUSCURI6' class='OUSCURI' value='"+(localStorage.getItem("OUSC6")||"")+"' /></td></tr>"+
			"<tr style='background-color: #FFFFFF;'><td class='key'>7</td><td><input type='text' id='OUSCURI7' class='OUSCURI' value='"+(localStorage.getItem("OUSC7")||"")+"' /></td></tr>"+
			"<tr style='background-color: #E0E0E0;'><td class='key'>8</td><td><input type='text' id='OUSCURI8' class='OUSCURI' value='"+(localStorage.getItem("OUSC8")||"")+"' /></td></tr>"+
			"<tr style='background-color: #FFFFFF;'><td class='key'>9</td><td><input type='text' id='OUSCURI9' class='OUSCURI' value='"+(localStorage.getItem("OUSC9")||"")+"' /></td></tr>"+
			"</table>").append($setBtn, $closeBtn).unbind("submit").submit(function() {
				var cnt = 0;
				$(".OUSCURI").each(function() {
					var _key_ = "OUSC"+cnt;
					localStorage.removeItem(_key_);
					localStorage.setItem(_key_, $.trim($(this).val()));
					cnt++;
				});
				hide();
				if(window.confirm("단축키 적용을 위해 새로고침을 수행합니다.")) window.location.reload();
				else window.alert("다음번 페이지 이동시부터 단축키가 적용됩니다.");
				return false;
			});
			var $set = $("<div />").attr("id", "__OUSCSET__").css({width: "350px", height: "370px"}).center().append($setForm.append("<div class='author'>By 종로구청 | <a href='./view.php?table=databox&no=1111132954'>문의하기</a></div>"));
			$("body").append($back.hide(), $set.hide());
		};
	};
	$(window).unbind("resize").resize(function() {
		$("div#__OUSCSET__").center();
	});
	$(document).unbind("keyup").keyup(function(e) {
		if(typeof(localStorage) != "undefined") {
			var evt = e || window.event;
			if(evt.target.tagName.toUpperCase() == "INPUT" || evt.target.tagName.toUpperCase() == "TEXTAREA") return;
			var id = "", uri = "http://todayhumor.co.kr/board/list.php?table=";
			if(evt.which == 27) {
				$("div#__OUSCBACK__").hide();
				$("div#__OUSCSET__").hide();
				$(document.documentElement).css({overflow: "scroll"});
			} else {
				if(evt.which == 37 || evt.which == 39) {
					var page = OUSC.getParam("page");
					if(evt.which == 37) page -= (page - 1 < 1) ? 0 : 1;
					else if(evt.which == 39) page += 1;
					/*
					페이지 위아래 스크롤을 화살표로 하는 경우가 있어서 잠시 보류
					else if(evt.which == 38) page = Math.floor(page/10) * 10 + ((page%10==0)?1:11);
					else if(evt.which == 40) page = (page > 10) ? Math.floor(page/10) * 10 - ((page%10==0)?19:9) : 1;
					else window.alert("??? Error!");
					*/
					id = uri+OUSC.getParam("table")+
						"&search_table_name="+OUSC.getParam("table")+
						"&page="+page+
						"&keyfield="+(OUSC.getParam("keyfield")||"")+
						"&keyword="+(OUSC.getParam("keyword")||"");
				} else {
					switch(evt.which) {
						case 48: case 96:	id = (localStorage.getItem("OUSC0")!=null)?localStorage.getItem("OUSC0"):"";	break;
						case 49: case 97:	id = (localStorage.getItem("OUSC1")!=null)?localStorage.getItem("OUSC1"):"";	break;
						case 50: case 98:	id = (localStorage.getItem("OUSC2")!=null)?localStorage.getItem("OUSC2"):"";	break;
						case 51: case 99:	id = (localStorage.getItem("OUSC3")!=null)?localStorage.getItem("OUSC3"):"";	break;
						case 52: case 100:	id = (localStorage.getItem("OUSC4")!=null)?localStorage.getItem("OUSC4"):"";	break;
						case 53: case 101:	id = (localStorage.getItem("OUSC5")!=null)?localStorage.getItem("OUSC5"):"";	break;
						case 54: case 102:	id = (localStorage.getItem("OUSC6")!=null)?localStorage.getItem("OUSC6"):"";	break;
						case 55: case 103:	id = (localStorage.getItem("OUSC7")!=null)?localStorage.getItem("OUSC7"):"";	break;
						case 56: case 104:	id = (localStorage.getItem("OUSC8")!=null)?localStorage.getItem("OUSC8"):"";	break;
						case 57: case 105:	id = (localStorage.getItem("OUSC9")!=null)?localStorage.getItem("OUSC9"):"";	break;
						default: return;
					}					
				}
				if(id!="") {
					if(id.indexOf("http://",0) != -1) window.location.href = id;
					else window.location.href = uri+id;
				}
			}
		}
		return false;
	});
	var OUSC = new OUShortCut();
	OUSC.init(getID());
}, 1);